****************************************************************************************
* Title: Graphical display of number of studies and (B) sample size by design type
* Manuscript Ref : Figure 2 of the manuscript
* Version: 14.2
* Required packages: catplot; stripplot 
****************************************************************************************

version 14.2

*Install required packages if needed
foreach package in catplot stripplot {
cap which `package'
if _rc {
ssc install `package'
}
}

*Select your preferred scheme file here - the scheme used is available as scheme-iddocovid.scheme
local local_scheme = "iddocovid"

*Change to folder where the dataset is stored
cd "filepath"
use 2020-05-07_iddo_lsr_covid-19_sr.dta, clear

*Change to folder where you want results saved
cd "filepath"


*Keep one record per study for a study-level database
keep if pickone_study_level_record==1

*Generate a st_design group variable ordered by frequency for panel B
decode st_design, gen(st_design_string)
bysort st_design: egen st_design_count = count(st_design)
egen st_design_grp1 = group(st_design_count st_design)
labmask st_design_grp1, values(st_design_string)


*Panel A graph - Number of studies by study design
catplot st_design ///
, var1opts(sort(1) descending) scheme(`local_scheme') ytitle(Number of studies) ///
blabel(bar, position(outside) format(%3.0f)) l1title("") ///
title("{bf: A}", size(large) position(10) color(black) ) ///
saving(Figure2A, replace)
foreach file_format in pdf emf tif {
graph export Figure2A.`file_format', replace
}

*Panel B graph - Sample sizes by study design
stripplot st_sample, box over(st_design_grp1) ///
 stack h(0.8) centre msize(vsmall) msymbol(Oh) scheme(`local_scheme') mcolor(black) ///
 box(bfcolor(red) blcolor(white) barw(0.9)) xtitle(Study sample size) ///
 title("{bf: B}", size(large) position(10) color(black) ) ///
xscale(log) xlabel(1 10 100 1000 10000 100000 1000000) xlabel(, angle(0)) ytitle("") saving(Figure2B, replace)
foreach file_format in pdf emf tif {
graph export Figure2B.`file_format', replace
}

*Combine panel A and B
gr combine Figure2A.gph Figure2B.gph, scheme(`local_scheme') rows(2) imargin(tiny)
foreach file_format in pdf emf tif {
graph export Figure2.`file_format', replace
}
